package com.landscope.issue.service.applet;

import com.landscope.issue.controller.base.ResponseResult;
import com.landscope.issue.controller.wx.dto.AppletMainMessageDto;
import com.landscope.issue.controller.wx.param.AppletMainGetNoticeParam;
import com.landscope.issue.mapper.MessageMapper;
import com.landscope.issue.utils.TokenUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ApiAppletMainService {

    @Resource
    private MessageMapper messageMapper;

    public ResponseResult<AppletMainMessageDto> message(AppletMainGetNoticeParam param) {
        TokenUtil.verifyAuthority(param.getAccessToken(),param.getProjectCode());
        // 查找未读消息数量，以及置顶消息
        List<AppletMainMessageDto.AppletMainMessageItemDto> list = messageMapper.findTopMessage(param.getProjectCode());

        Integer messageNum = messageMapper.findUnReadNum(param.getProjectCode());

        AppletMainMessageDto appletMainMessageDto = new AppletMainMessageDto();
        appletMainMessageDto.setMessageNum(messageNum);
        appletMainMessageDto.setMessageList(list);
        return new ResponseResult<AppletMainMessageDto>().success().setData(appletMainMessageDto);
    }
}
